<?php

namespace app\adminapi\controller\v1\marketing\score;

use app\adminapi\controller\AuthController;
use app\Request;
use app\services\activity\score\StoreScoreTaskServices;
use think\facade\App;

class StoreScoreTask extends AuthController
{
    protected $services;
    /**
     * StoreIntegralOrder constructor.
     * @param App $app
     * @param StoreScoreOrder $service
     * @method temp
     */
    public function __construct(App $app, StoreScoreTaskServices $service)
    {
        parent::__construct($app);
        $this->services = $service;
    }

    public function list(Request  $request){
        $list = $this->services->list();
        return app('json')->success($list);
    }

    /**
     * 完成积分任务
     * @param Request $request
     * @return mixed
     */
    public function finish(Request $request)
    {
        $data = $request->getMore([
            ['task_id', 0],
        ]);
        if (!$data['task_id']) {
            return app('json')->fail(400802);
        }
        $user = $request->user()->toArray();
        $this->services->finish($data['task_id'],$user);
        return app('json')->success($data);
    }
}
